#include "Utils.h"
#include "persistable.h"
using namespace xml_api;
using namespace std;

Utils::Utils(void)
{
}

Utils::~Utils(void)
{
}

void Utils::DeserializeFromFile( const string& file_name, Persistable* persistable )
{
  Serializer* serializer= CreateFileSerializer(file_name);
  serializer->Deserialization(persistable);
  delete serializer;
  serializer = NULL;
}

void Utils::DeserializeFromBuffer( const string& buffer, Persistable* persistable )
{
  Serializer* serializer= CreateBufferSerializer(buffer);
  serializer->Deserialization(persistable);
  delete serializer;
  serializer = NULL;
}

void Utils::Serialize( const string& file_name,Persistable* persistable )
{
  Serializer* serializer= CreateFileSerializer(file_name);
  serializer->Serialization(persistable);
  delete serializer;
  serializer = NULL;
}

xml_api::Serializer* Utils::CreateFileSerializer( const string& file_name )
{
  return new XmlFileSerializer(file_name);
}

xml_api::Serializer* Utils::CreateBufferSerializer( const string& buffer )
{
  return new XmlBufferSerializer((char*)buffer.c_str(), buffer.size());
}
